#include "qtquick1applicationviewer.h"
#include <QCoreApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <QtDeclarative>
#include "worker.h"
#include "usbdevice.h"
#include "myApplication.h"

int main(int argc, char *argv[])
{
    MyApplication app(argc, argv);
    //qmlRegisterType<Usbdevice>("USBDevice", 1, 0, "Usbdevice");

    QtQuick1ApplicationViewer viewer;
    viewer.setWindowOpacity(1);
    viewer.setWindowFlags(Qt::FramelessWindowHint);
    viewer.setAttribute(Qt::WA_TranslucentBackground);
    viewer.setStyleSheet("background:transparent;");
    viewer.addImportPath(QLatin1String("modules"));
    viewer.setOrientation(QtQuick1ApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qrc:/main.qml"));
    viewer.showExpanded();
    Usbdevice usbDisk(&app);
    viewer.rootContext()->setContextProperty("mainWindow",&viewer);
    viewer.rootContext()->setContextProperty("USB",&usbDisk);
    QObject::connect(&app, SIGNAL(usbDiskInserted(QVariant, QVariant, QVariant, QVariant)),
                         (QObject *)(viewer.rootObject()), SLOT(onUsbDiskInserted(QVariant, QVariant, QVariant, QVariant)));
    QObject::connect(&app, SIGNAL(usbDiskRemoved(QVariant)),
                         (QObject *)(viewer.rootObject()), SLOT(onUsbDiskRemoved(QVariant)));
    QObject::connect((QObject *)(viewer.rootObject()), SIGNAL(makeClonezillaDevice(int, QString, QString)),
                         &usbDisk, SLOT(onMakeClonezillaDevice(int, QString, QString)), Qt::QueuedConnection);
    QObject::connect(&(usbDisk.w), SIGNAL(doingPercent(QVariant, QVariant)),
                         (QObject *)(viewer.rootObject()), SLOT(onDoingPercent(QVariant, QVariant)), Qt::QueuedConnection);
    app.getInsertedUSBDevices();
    return app.exec();
}
